package com.zlp.factory;

import com.zlp.enums.SupplierTypeEnum;
import com.zlp.stategy.CouponSupplierStategy;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: 工厂模式调用
 * @author: LiPing.Zou
 * @create: 2020-05-08 21:43
 */
@Component
public class SupplierCouponFactory {
  static final Map<Integer, Object> beanStrategyMap = new HashMap<>(4);

  @Resource(name = "ysCouponSupplierStategyImpl")
  private CouponSupplierStategy ysCouponSupplierStategyImpl;

  @Resource(name = "lhCouponSupplierStategyImpl")
  private CouponSupplierStategy lhCouponSupplierStategyImpl;


  @PostConstruct
  protected void initStrategy() {
    beanStrategyMap.put(SupplierTypeEnum.LI_HAN.getCode(), lhCouponSupplierStategyImpl);
    beanStrategyMap.put(SupplierTypeEnum.YUNSHENG_FUTURE.getCode(), ysCouponSupplierStategyImpl);
  }

  public static CouponSupplierStategy invokeExecutor(Integer spuType) {

    return (CouponSupplierStategy) beanStrategyMap.get(spuType);
  }
}
